/**
 * sysRolePermissionServiceImpl
 * 项目名称:分秒金融
 *
 * @author lunli
 *
 * 功能描述:角色资源管理
 * 
 * 历史版本:2017-03-28 v1.0.0 lunli  创建:
 * 
 */
package com.fmjr.sys.sysRolePermission.service.impl;

import com.fmjr.common.base.exception.BusinessException;
import com.fmjr.common.base.util.Pager;
import com.fmjr.common.util.SqlUtil;
import com.fmjr.sys.sysRolePermission.bean.SysRolePermission;
import com.fmjr.sys.sysRolePermission.dao.SysRolePermissionDao;
import com.fmjr.sys.sysRolePermission.service.ISysRolePermissionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;


@Service("sysRolePermissionService")
public class  SysRolePermissionServiceImpl implements ISysRolePermissionService {
	

	@Autowired
    private SysRolePermissionDao sysRolePermissionDao;

	/**
	 * 根据条件查询角色资源记录
	 * @author lunli
	 * @param  pager
	 * @return SysRolePermissionList
	 * @throws BusinessException
	 */
	public void selectSysRolePermissionList(Pager<SysRolePermission> pager) throws BusinessException{
		int totalCount = sysRolePermissionDao.selectSysRolePermissionCount(pager);
		int numPerPage = SqlUtil.checkPageSize(pager.getNumPerPage());
		int currentPage = SqlUtil.checkPageCurrent(totalCount, numPerPage, pager.getPageNum());
		pager.setLimitStart(SqlUtil.countOffset(currentPage, numPerPage));
		pager.setPageSize(numPerPage);
		pager.setCurrentPage(currentPage);
		pager.setTotalCount(totalCount);
		pager.setTotalPage(totalCount%numPerPage==0?totalCount/numPerPage:totalCount/numPerPage+1);
		List<SysRolePermission> list = sysRolePermissionDao.selectSysRolePermissionList(pager);
		pager.setList(list);
	}
	
	/**
	 * 根据ID查询角色资源记录
	 * @author lunli
	 * @param id
	 * @return domain
	 * @throws BusinessException
	 */
	public SysRolePermission selectSysRolePermissionById(Long id) throws BusinessException{
		return sysRolePermissionDao.selectSysRolePermissionById(id);
	}

	/**
	 *  删除角色资源记录
	 * @author lunli	 
	 * @param id
	 * @throws BusinessException
	 */
	@Transactional(rollbackFor=BusinessException.class)
	public int deleteSysRolePermissionById(Long id) throws BusinessException{
		return sysRolePermissionDao.deleteSysRolePermissionById(id);
	}
	
	/**
	 * 修改角色资源记录
	 * @author lunli
	 * @param sysRolePermission
	 * @throws BusinessException
	 */
	@Transactional(rollbackFor=BusinessException.class)
	public int updateSysRolePermission(SysRolePermission sysRolePermission) throws BusinessException{
		return sysRolePermissionDao.updateSysRolePermission(sysRolePermission);
	}

	/**
	 * 新增角色资源记录
	 * @author lunli
	 * @param sysRolePermission
	 * @return
	 * @throws BusinessException
	 */
	@Transactional(rollbackFor=BusinessException.class)
	public int createSysRolePermission(SysRolePermission sysRolePermission) throws BusinessException{
		return sysRolePermissionDao.createSysRolePermission(sysRolePermission);
	}

	@Override
	public List<SysRolePermission> searchRolePermissionByRoleId(Long roleId) throws BusinessException {
		return sysRolePermissionDao.searchRolePermissionByRoleId(roleId);
	}
	

	

}
